import type { CSSProperties } from 'vue'
import { PageInfo } from '@/types/request'

export type Align = 'left' | 'center' | 'right'

export type Column<T = Record<string, any>> = {
  title?: string
  minWidth?: number
  maxWidth?: number
  width?: number
  height?: number
  align?: Align
  fixed?: 'right' | 'left'
  // getText() 值转换
  format?: 'date' | 'datetime' | 'time' | 'image' | 'html' | 'dict'
  // 当 format = dict, 选填，默认 key
  dict?: string
  // 获取显示值
  getText?: ((row: T, text: any) => string | null | undefined)
  thStyle?: CSSProperties
  thClass?: string
  style?: CSSProperties | ((row: T, index: number) => CSSProperties)
  class?: string | ((row: T, index: number) => string)
} & ({ key: Partial<keyof T>, type?: 'index' | 'selection' } | { key?: Partial<keyof T>, type: 'index' | 'selection' | 'operation' })

export type Columns<T = Record<string, any>> = Column<T>[]

export type Pageable = {
  perpage: number
  page: number
  total: number
}

// 分页选中数据
export type Selection<T = string | number> = {
  // 是否选择所有
  isAll: boolean
  // 根据 isAll 变换状态 isAll ? not in keys : in keys
  keys: T[]
  // 当前页选中
  currentKeys: T[]
  // 选中统计
  count: number
}

export type PageableHook = Pageable & {
  /**
   * 重置
   */
  reset(): void
  /**
   * 重置 page = 1
   */
  resetPage(): void
  /**
   * 获取请求参数
   */
  getReq(): PageInfo
}
